package com.adcc.ags.gms.mq.vo;

import com.adcc.ags.gms.core.entity.BaseEntity;
import com.adcc.ags.gms.core.vo.BaseVO;
import com.adcc.utility.mq.entity.ibm.IBMTopic;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 会话视图
 */
public class TopicVO extends BaseVO {

    // 名称
    private String name;

    // 类型1
    private String type;

    // 优先级
    private int priority;

    // 持久化
    private boolean persistent;

    // 进队列数
    private long enqueued;

    // 出队列数
    private long dequeued;

    // 生产者
    private long producers;

    // 消费者
    private long consumers;

    /**
     * 构造函数
     */
    public TopicVO(){

    }

    /**
     * 构造函数
     * @param topic
     */
    public TopicVO(IBMTopic topic){
        if(topic != null){
            name = topic.getName();
            if(topic.getType() == IBMTopic.CONSTANT_ALL){
                type = "所有主题";
            }else if(topic.getType() == IBMTopic.CONSTANT_CLUSTER){
                type = "集群主题";
            }else{
                type = "本地主题";
            }
            priority = topic.getPriority();
            persistent = topic.isPersistent();
            enqueued = topic.getEnqueued();
            dequeued = topic.getDequeued();
            producers = topic.getProducers();
            consumers = topic.getConsumers();
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public boolean isPersistent() {
        return persistent;
    }

    public void setPersistent(boolean persistent) {
        this.persistent = persistent;
    }

    public long getEnqueued() {
        return enqueued;
    }

    public void setEnqueued(long enqueued) {
        this.enqueued = enqueued;
    }

    public long getDequeued() {
        return dequeued;
    }

    public void setDequeued(long dequeued) {
        this.dequeued = dequeued;
    }

    public long getProducers() {
        return producers;
    }

    public void setProducers(long producers) {
        this.producers = producers;
    }

    public long getConsumers() {
        return consumers;
    }

    public void setConsumers(long consumers) {
        this.consumers = consumers;
    }

    @Override
    public BaseEntity toEntity() {
        return null;
    }

    @Override
    public String toJson() throws JsonProcessingException {
        return new ObjectMapper().writeValueAsString(this);
    }
}
